package com.dreem.factory.factorymethod.pizzastore.order;

import com.dreem.factory.factorymethod.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @program: DesignParrtern
 * @description: 订购披萨抽象类
 * @author: Peng
 * @create: 2021-01-24  17:45
 **/
public abstract class OrderPizza {
    // 定义一个抽象方法，createPizza，让各个工厂子类自己实现
    abstract Pizza createPizza(String orderType);
    private BufferedReader bufferedReader = null;
    // 构造器

    public OrderPizza() {
        Pizza pizza = null;
        String orderType;//订购披萨的类型
        do{
            orderType = getType();
            if(orderType.equalsIgnoreCase("exit")){
                closeStream();
                break;
            }
            pizza = createPizza(orderType);
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        }while(true);
    }

    // 获取客户希望订购的披萨种类
    private String getType() {
        try{
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 的种类：");
            String str = bufferedReader.readLine();
            return str;
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }
    private void closeStream(){
        if(bufferedReader != null){
            try {bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
